package com.fingard.dsp.bank.reqrespobj.subaccount;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.qryrefund.detail.RetAtsRefundDetail;
import com.fingard.dsp.bank.reqrespobj.subaccount.detail.RetAtsSubAccountDetail;
import com.fingard.xml.XmlTextWriter;

/**
 * @Description TODO
 * @Author xtt
 * @Date $ $
 **/
public class RetAtsSubAccountInfo extends RetAtsBase {
    public String reqSeqID = "";
    public String totleNum = "";

    public RetAtsSubAccountInfo(ReqRespHeader p_header) {
        retHeader = p_header;
        reqSeqID = p_header.reqSeqID;
        retXmlWriter = new XmlTextWriter();
    }

    private int writeRdCount = 0;

    public int getWrittenRdCount() {
        return writeRdCount;
    }

    public boolean hasWrittenTotleNum = false;
    public boolean hasWrittenTotleAmount = false;
    public void writeTotalInfo() throws Exception {
        if(hasWrittenTotleNum) {
            throw new Exception("重复写入TotleNum");
        }
        if(hasWrittenTotleAmount) {
            throw new Exception("重复写入TotleAmount");
        }
        retXmlWriter.writeElementString("TotleNum", totleNum);
        hasWrittenTotleNum = true;
        hasWrittenTotleAmount = true;
    }

    public void writeRetDetail(RetAtsSubAccountDetail p_retDetail) throws Exception {
        writeRdCount++;
        if (writeRdCount == 1) {
            if (!hasWrittenRespCode) {
                writeRespCode("0");
            }
            if (!hasWrittenRespInfo) {
                writeRespInfo("");
            }
            retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        }

        retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        retXmlWriter.writeElementString("TotleNum", totleNum);

        retXmlWriter.writeStartElement("DetailRecord");
        p_retDetail.writeXE(retXmlWriter);
        retXmlWriter.writeEndElement();
    }
}
